<template>
    <div id="newgoods">
        <el-button icon='el-icon-refresh' class="filter-item" @click="handleReset">刷新</el-button>
<!--        <%&#45;&#45;点击驳回弹出来的 驳回理由对话框&#45;&#45;%>-->
        <el-dialog
                title="驳回理由"
                :visible.sync="dialogVisible"
                width="30%"
        >
            <el-form ref="form" :model="bohuifrom" label-width="80px">
                <el-form-item label="驳回理由">
                    <el-input type="textarea" v-model="bohuifrom.msg"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="bohui">确 定</el-button>
                </span>
        </el-dialog>
        <el-table
                :data="newgoodsData"
                style="width: 100%"
                border
                row-key="id"
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                :default-expand-all="false">
            <el-table-column
                    prop="id"
                    label="编号"
                    width="170"
            >
            </el-table-column>
            <el-table-column
                    prop="gname"
                    label="商品名称"
                    width="80"
            >
            </el-table-column>
            <el-table-column
                    prop="img"
                    label="商品图片"
                    width="80"
            >
                <template slot-scope="scope">
                    <el-popover placement="right" trigger="hover">
                        <img :src="scope.row.img" width="250" height="200">
                        <img slot="reference" :src="scope.row.img"  style="width:70px;height:35px">
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column
                    prop="description"
                    label="商品描述"
                    width="80"
            >
            </el-table-column>
            <el-table-column
                    prop="code"
                    label="商品编码"
                    width="80"
            >
            </el-table-column>
            <el-table-column

                    prop="typename"
                    label="商品类别"

            >
            </el-table-column>
            <el-table-column

                    prop="gsname"
                    label="商品规格"
            >
            </el-table-column>
            <el-table-column

                    prop="gbname"
                    label="商品品牌"
            >
            </el-table-column>
            <el-table-column

                    prop="gdname"
                    label="存储方式"
            >
            </el-table-column>

            <el-table-column
                    prop="start"
                    label="审核状态">
                <template slot-scope="scope">
                    <el-tag   v-if="scope.row.start==2">等待审核</el-tag>
                    <el-tag type="success" v-if="scope.row.start==0">审核通过</el-tag>
                    <el-tag type="danger" v-if="scope.row.start==1">审核驳回</el-tag>
                </template>
            </el-table-column>
            <el-table-column

                    prop="gmt_create"
                    label="创建时间"
            >
            </el-table-column>
            <el-table-column

                    prop="gmt_modified"
                    label="更新时间"
            >
            </el-table-column>

            <el-table-column
                    label="操作方法"
                    width="200"
            >
                <template slot-scope="scope">
                    <el-button type="success" icon="el-icon-thumb" size="mini"  @click="tongguo(scope.row)">通过</el-button>
                    <el-button type="danger"  icon="el-icon-error" size="mini" @click="onSubmit(scope.row.id)">驳回</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "newgoods",
        data(){
            return {
                //驳回理由内容
                bohuifrom:{},
                newgoodsData:[],
                //当前页数
                currentPage:1,
                pageSizes:[5,10,15,20],
                //每页显示的条数
                pageSize:5,
                //总条数
                total:0,
                //弹出框状态
                dialogVisible:false,
                tg:{

                }
            }
        },
        created() {
          this.newgoods();
        },
        methods:{
            //审核驳回事件触发
            bohui(){
               var that =this
                this.dialogVisible=false;
                this.$http.post("/goods/newgoods/reject/"+this.id,this.bohuifrom).then(function (res){
                    if(res.data.code===2000) {
                        that.newgoods();
                        that.$message.success(res.data.msg);
                    }
                })
            },
            //审核通过触发
            tongguo(row){
                var that=this;
              this.tg=row
                this.$http.post("/goods/newgoods/pass",this.tg).then(function (res){
                    //console.log(res);
                     if(res.data.code===2000) {
                         that.newgoods();
                         that.$message.success(res.data.msg);
                     }else if(res.data.code===5000){
                        that.$message.error(res.data.msg);
                    }
                })
            },
            //按下驳回按钮弹出内容
            onSubmit(id){
                this.dialogVisible=true;
                this.id=id;
                this.newgoods()

            },
            //每页显示的条数发生改变时触发
            handleSizeChange(val) {
                this.pageSize=val;
                this.newgoods()
            },
            //当前页码发生改变时触发
            handleCurrentChange(val) {
                this.currentPage=val;
                this.newgoods()
            },
            handleReset() {
                this.newgoods()

            },
            newgoods(){
                var that =this
                this.$http.post('/goods/newgoods/select/'+this.currentPage+"/"+this.pageSize).then(function (resp) {
                    //console.log(resp)
                    that.newgoodsData=resp.data.data.records
                    that.total=resp.data.data.total

                })
            },
        }
    }
</script>

<style scoped>

</style>